#ifndef HASIO_IP_DETAIL_ENDPOINT_IMPL_HPP
#define HASIO_IP_DETAIL_ENDPOINT_IMPL_HPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#include "../../detail/socket_ops.hpp"

namespace hasio {
namespace ip {
namespace detail {

class endpoint_impl
{
public:
    endpoint_impl()
        : data_()
    {
    }

    endpoint_impl(int family, unsigned short port)
        : data_()
    {
        if (family == SOCKET_DEF(AF_INET))
        {
            data_.v4.sin_family = SOCKET_DEF(AF_INET);
            data_.v4.sin_port = hasio::detail::socket_ops::host_to_network_short(port);
            data_.v4.sin_addr.s_addr = SOCKET_DEF(INADDR_ANY);
        }
        else
        {
        }
    }

    bool is_v4() const
    {
        return data_.base.sa_family == SOCKET_DEF(AF_INET);
    }

    hasio::detail::ushort_type port() const
    {
        if (is_v4())
        {
            return hasio::detail::socket_ops::network_to_host_short(
                data_.v4.sin_port);
        }
        else
        {
            return hasio::detail::socket_ops::network_to_host_short(
                data_.v6.sin6_port);
        }
    }

private:
    union data_union
    {
        hasio::detail::socket_addr_type base;
        hasio::detail::socket_addr_in4_tpye v4;
        hasio::detail::socket_addr_in6_tpye v6;
    } data_;
};

}
}
}

#endif // HASIO_IP_DETAIL_ENDPOINT_IMPL_HPP